<template>
  <div>
    附件：
    <div v-for="(item, i) in row.fileMc" style="margin-bottom: 5px">
      <el-button
        style="margin-left: 20px"
        type="danger"
        icon="el-icon-delete"
        circle
        size="mini"
        :disabled="shztGhb === '1' || row.shzt == '1' || row.shzt === '5'"
        @click="delFileBySort(i, row.id)"
      >
      </el-button>
      <el-link type="primary" @click="showFile(row.fileUrl[i])">
        {{ i + 1 }} 、 {{ item }}
      </el-link>
    </div>
  </div>
</template>

<script>
export default {
  methods: {
    subInfo(subType, formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let msgCont = "";
          let confirmSave = false; // Flag to determine if a save confirmation should be shown

          // Determine the action message and whether to show a confirmation for saving
          if (subType === -1) {
            msgCont = "保存";
            if (this.shztGhb !== "-1") {
              confirmSave = true;
            }
          } else {
            msgCont = "上报";
          }

          // Handle save action with confirmation (if required)
          if (confirmSave) {
            this.$message({
              message: "保存成功，如上报省委组织部，需再次点击上报按钮完成上报",
              type: "success",
            });
          } else {
            // Handle save or report action with confirmation dialog (if not a save with shztGhb !== '-1')
            const confirmMessage = `是否${msgCont}?`;
            this.$confirm(confirmMessage, "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            })
              .then(() => {
                this.performAction(subType, msgCont);
              })
              .catch(() => {
                this.$message({
                  type: "info",
                  message: "已取消操作!",
                });
              });
          }
        } else {
          return false;
        }
      });
    },

    performAction(subType, msgCont) {
      this.pageLoading = true;
      const scort = {
        scoreZp1: this.infoData[0].zpfz,
        scoreZp2: this.infoData[this.hzColumn.zrlsqkColumn].zpfz,
        scoreZp3: 30,
        scoreZp4:
          this.infoData[
            this.hzColumn.zrlsqkColumn + this.hzColumn.fxpyqkColumn + 1
          ].zpfz,
        taskId: this.taskId,
      };
      const params = {
        infoData: this.infoData,
        scorts: scort,
        userInfo: this.userInfo,
        task: this.task,
        subType: subType, // Reporting status
        assessYear: this.assessYear,
      };

      // Add jlzbFile parameter only for assessYear === "2024"
      if (this.assessYear === "2024") {
        params.jlzbFile = this.jlzbFile;
      }

      const saveMethod =
        this.assessYear === "2024" ? saveInfoData2024 : saveInfoData;

      saveMethod(params)
        .then((result) => {
          if (result.result) {
            this.pageLoading = false;
            this.$alert(msgCont + "成功!", {
              confirmButtonText: "确定",
              callback: (action) => {
                this.initFillingData(this.assessYear);
              },
            });
          }
        })
        .catch((err) => {
          this.$message({
            message: "系统错误，请重新登录再试。",
            type: "warning",
          });
        });
    },
  },
};
</script>

<style>
</style>